var health : float;
private var healthLeft : float;
private var hb: HealthBar = null;
//for Testing
private var startTime;
private var flash;
var flashDuration : float = .5;
var transparency : float = .2;

private var sc : SoundController = null;;

function Start() {
  sc = GetComponent("SoundController");
	healthLeft = health;
	flash = GameObject.Find("blood");
    var gameobject = GameObject.Find("Player");
    // (ScriptName is the name of the javascript file)
    hb = gameobject.GetComponent("HealthBar");
    hb.setHealth(health);
    startTime = Time.time;
}

function Update(){
  
}

function hit(){
	healthLeft--;
    sc.HurtSound();
    hb.updateHealth(healthLeft, health);
	FlashWhenHit();
	//print (healthLeft);
	if (healthLeft <= 0) {
		print ("Player Dead");
	}
}

function healthPowerUp(){
	healthLeft++;
	hb.updateHealth(healthLeft, health);
	//print (healthLeft);
}

function Fade (start : float, end : float, length : float, currentObject : GameObject) { //define Fade parmeters
if (currentObject.guiTexture.color.a == start){

for (i = 0.0; i < 1.0; i += Time.deltaTime*(1/length)) { //for the length of time
currentObject.guiTexture.color.a = Mathf.Lerp(start, end, i); //lerp the value of the transparency from the start value to the end value in equal increments
yield;
currentObject.guiTexture.color.a = end; // ensure the fade is completely finished (because lerp doesn't always end on an exact value)
        } //end for

} //end if

} //end Fade

function FlashWhenHit (){
    Fade (0, transparency, 0.2, flash);
    yield WaitForSeconds (flashDuration);
    Fade (transparency, 0, 0.2, flash);
    }